#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
    char name[50];
    int number;
    char position[20];
    int age;
} Player;
void addPlayer(Player players[], int *numPlayers);
void deletePlayer(Player players[], int *numPlayers);
void modifyPlayer(Player players[], int numPlayers);
void searchPlayer(Player players[], int numPlayers);
void addPlayer(Player players[], int *numPlayers) {
    if (*numPlayers >= 18) {
        printf("球员数量已达上限，无法添加新球员！\n");
        return;
    }

    printf("\n添加球员信息：\n");
    printf("请输入球员姓名：");
    scanf("%s", players[*numPlayers].name);
    printf("请输入球员号码：");
    scanf("%d", &players[*numPlayers].number);
    printf("请输入球员位置：");
    scanf("%s", players[*numPlayers].position);
    printf("请输入球员年龄：");
    scanf("%d", &players[*numPlayers].age);

    printf("球员信息添加成功！\n");
    (*numPlayers)++;
}
void deletePlayer(Player players[], int *numPlayers) {
    int deleteNumber;
    printf("\n请输入要删除球员的号码：");
    scanf("%d", &deleteNumber);
    int found = 0;
    for (int i = 0; i < *numPlayers; i++) {
        if (players[i].number == deleteNumber) {
            for (int j = i; j < *numPlayers - 1; j++) {
                players[j] = players[j + 1];
            }
            (*numPlayers)--;
            found = 1;
            printf("球员信息删除成功！\n");
            break;
        }
    }
    if (!found) {
        printf("未找到该球员号码对应的球员信息！\n");
    }
}
void modifyPlayer(Player players[], int numPlayers) {
    int modifyNumber;
    printf("\n请输入要修改球员的号码："); 
    scanf("%d", &modifyNumber);
    int found = 0;
    for (int i = 0; i < numPlayers; i++) {
        if (players[i].number == modifyNumber) {
            printf("请输入修改后的球员信息：\n");
            printf("姓名：");
            scanf("%s", players[i].name);
            printf("位置：");
            scanf("%s", players[i].position);
            printf("年龄：");
            scanf("%d", &players[i].age);
            found = 1;
            printf("球员信息修改成功！\n");
            break;
        }
    }
    if (!found) {
        printf("未找到该球员号码对应的球员信息！\n");
    }
}
void searchPlayer(Player players[], int numPlayers) {
    int searchNumber;
    printf("\n请输入要查询球员的号码：");
    scanf("%d", &searchNumber);
    int found = 0;
    for (int i = 0; i < numPlayers; i++) {
        if (players[i].number == searchNumber) {
            printf("球员信息：\n");
            printf("姓名：%s\n", players[i].name);
            printf("号码：%d\n", players[i].number);
            printf("位置：%s\n", players[i].position);
            printf("年龄：%d\n", players[i].age);
            found = 1;
            break;
        }
    }
    if (!found) {
        printf("未找到该球员号码对应的球员信息！\n");
    }
}
 void welcome(){
	printf("****************************\n");
	printf("       足球队信息管理系统       \n");
	printf("     增加球员数据信息-----1     \n");
	printf("     删除球员数据信息-----2     \n");
	printf("     修改球员数据信息-----3     \n");
	printf("     搜索球员数据信息-----4     \n");
	printf("         Quit-----0             \n");
	printf("********************************\n");
    printf("       请输入对应选项：     \n");
}
void welcome();
int main(int argc, char *argv[]) 
  {
    int choice=0;
    Player players[100];
    int numPlayers = 0;
    do{
	welcome();
	scanf("%d",&choice);
    switch (choice) {
        case 1:
            addPlayer(players, &numPlayers);
            break;
        case 2:
            deletePlayer(players, &numPlayers);
            break;
        case 3:
            modifyPlayer(players, numPlayers);
            break;
        case 4:
            searchPlayer(players, numPlayers);
            break;
        case 0:
            printf("感谢使用！\n");
            break;
        default:
            printf("请选择有效操作！\n");
            break;
		}
		}while(choice!=0);
  	return 0;
}